var t_width = $("#plogw").attr("width");
var hot;
var hotdown;
var cell_data;
var cell_data_down;

// 我的项目日志添加记录
var ploginfoColumns = [{
    id: 'logTime',
    title: '日期',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.logTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'hourNum',
    title: '小时数',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        if (record.hourNum > 11) {
            content = "<span style='color:#FF6C60'>" + record.hourNum + "</span>"
        } else {
            content = record.hourNum
        }
        return content;
    }

}, {
    id: 'userName',
    title: '申请人',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    hideType: 'md|sm|xs',
}, {
    id: 'proName',
    title: '项目名称',
    type: 'string',
    width: 150,
    columnClass: 'text-center',
    hideType: 'md|sm|xs',
}
// , {
//     id: 'comments',
//     title: '事由',
//     type: 'string',
//     columnClass: 'text-left',
//     hideType: 'md|sm|xs',
// }
];

var ploginfoOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    // loadURL:'url',
    exportFileName: '项目日志添加记录',
    datas: [],
    extraWidth: 20,
    columns: ploginfoColumns,
    gridContainer: 'ploginfoContainer',
    toolbarContainer: 'ploginfoToolBarContainer',
    tools: '',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50]
};

var ploginfoGrid = $.fn.dlshouwen.grid.init(ploginfoOption);

function getGird(val, status, data) {
    if (status === "none") {
        $("#plogbox").show();
        $("#girdTitle").html(val);
        $("#lisplog").empty();
        $("#lisplog").html('<div id=\"ploginfoContainer\" class=\"dlshouwen-grid-container\"></div><div id=\"ploginfoToolBarContainer\" class=\"dlshouwen-grid-toolbar-container\"></div>')
        ploginfoOption.datas = data;
        ploginfoGrid = $.fn.dlshouwen.grid.init(ploginfoOption)
        ploginfoGrid.load();
    } else {
        $("#girdTitle").html(val);
        $("#lisplog").empty();
        $("#lisplog").html('<div id=\"ploginfoContainer\" class=\"dlshouwen-grid-container\"></div><div id=\"ploginfoToolBarContainer\" class=\"dlshouwen-grid-toolbar-container\"></div>')
        ploginfoOption.datas = data;
        ploginfoGrid = $.fn.dlshouwen.grid.init(ploginfoOption)
        ploginfoGrid.load();
    }
}

function prologselect($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {

    CertusFormAjax.ajax("stscompSelectByAutho", {"areaSelect": "XZZX-YGLB"}, function (res) {
        if (res.data) {
            // res.data.forEach(function (data) {
            //     $("#deptSelectId").append('<option  value="' + data.code + '">' + data.name + '</option>')
            // })
            for(var i = 0;i < res.data.length;i++){
                $("#deptSelectId").append('<option  value="' + res.data[i].code + '">' + res.data[i].name + '</option>')
            }
            $("#deptSelectId").selectpicker('refresh');
        }
    })

    $("#departmentSelectId").append('<option  value="' + "prolog" + '">' + "项目工时" + '</option>')
    $("#departmentSelectId").append('<option  value="' + "monthprolog" + '">' + "项目月表" + '</option>')
    // $("#departmentSelectId").append('<option  value="' + "prolog" + '">' + 项目工时 + '</option>')
    $("#departmentSelectId").selectpicker('refresh');

    function deptSelectRefresh() {
        $('#deptSelectId').val('')
        $("#deptSelectId").selectpicker('refresh');
    }

    function departmentSelectRefresh() {
        $('#departmentSelectId').val('')
        $('#departmentSelectId').selectpicker('refresh')
    }


    $scope.selectedAndDispatch = function () {
        CertusFormAjax.ajax("initOkrComp", {compselected: $("#deptSelectId").val()}, function (res) {
            window.location.href = "#" + $("#departmentSelectId").val()
        })
    }
}

function prologMonth($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    CertusFormAjax.ajax("okrSearchGroupByProjMonthOfYear", {year: $("#yeardown").val()}, function (res) {
        debugger
        getGird('項目按月', '', []);
        initProLogdownSimple(res, CertusFormAjax)
    })

    $scope.projNameChangeDown = function(a){
        debugger;
        if(!a){
            $scope.down.projId = ""
        }
    }

    $scope.down = {};

    $scope.searchProLogdown = function () {
        $(document.getElementById('plogtabledown')).empty();
        CertusFormAjax.ajax("okrSearchGroupByProjMonthOfYear", {
            year: $("#yeardown").val(),
            projId: $scope.down.projId
        }, function (res) {
            getGird('当前日所有员工记录', '', []);
            initProLogdown(res, CertusFormAjax)
        })
    }

    $scope.exprotPorjOkrLogdown = function () {
        CertusFormAjax.download("okrSearchGroupByProjMonthOfYearDown", "year=" + $("#yeardown").val() + "&projId=" + $scope.down.projId);
    }
}


function prolog($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $scope.projNameChangeUp = function(a){
        debugger;
        if(!a){
            $scope.up.projId = ""
        }
    }
    $scope.projNameChange = function(a){
        debugger;
        if(!a){
            $scope.down.projId = ""
        }
    }

    CertusFormAjax.ajax("okrSearchYearAndMonth", {year: $("#year").val(), month: $("#month").val()}, function (res) {
        getGird('当前日所有员工记录', '', []);
        initProLog(res, CertusFormAjax)
    })

    $scope.down = {};

    CertusFormAjax.ajax("okrSearchByYear", {year: $("#yeardown").val()}, function (res) {
        debugger
        getGird('当前日所有员工记录', '', []);
        initProLogdown(res, CertusFormAjax)
    })

    $scope.searchProLog = function () {
        $(document.getElementById('plogtable')).empty();
        CertusFormAjax.ajax("okrSearchYearAndMonth", {
            year: $("#year").val(),
            month: $("#month").val(),
            projId: $scope.up.projId
        }, function (res) {
            getGird('当前日所有员工记录', '', []);
            initProLog(res, CertusFormAjax)
        })
    }

    $scope.searchProLogdown = function () {
        $(document.getElementById('plogtabledown')).empty();
        CertusFormAjax.ajax("okrSearchByYear", {
            year: $("#yeardown").val(),
            projId: $scope.down.projId
        }, function (res) {
            getGird('当前日所有员工记录', '', []);
            initProLogdown(res, CertusFormAjax)
        })
    }

    $scope.exprotPorjOkrLog = function () {
        CertusFormAjax.download("downloadProjLog", "year=" + $("#year").val() + "&month=" + $("#month").val() + "&projId=" + $scope.projId);
    }

    $scope.exprotPorjOkrLogdown = function () {
        CertusFormAjax.download("downProjWorkByMonth", "year=" + $("#yeardown").val() + "&projId=" + $scope.down.projId);
    }

    $scope.exprotPorjOkrLog2 = function () {
        //at once proj export
        CertusFormAjax.download("onceProjLog", "year=" + $("#year").val() + "&month=" + $("#month").val() + "&projId=" + $scope.projId);
    }

    // $scope.$watch("projName", function (newValue, old, scope) {
    //     if (old && newValue) {
    //         scope.projId = "";
    //         scope.projName = "";
    //         if (newValue.indexOf(old) > -1) {
    //             ;
    //             nowProjName = newValue;
    //             scope.userProjSelect2 = scope.userProjSelect2.filter(isSaveProjName);
    //             if (scope.userProjSelect2.length) {
    //                 if (scope.userProjSelect2.length == 1) {
    //                     scope.projId = scope.userProjSelect2[0].projId;
    //                     scope.projName = scope.userProjSelect2[0].projName;
    //                     return;
    //                 }
    //             }
    //             if (!scope.userProjSelect2 || scope.userProjSelect2.length == 0) {
    //                 scope.projId = "";
    //                 scope.projName = "";
    //             }
    //             return;
    //         }
    //     }
    //     //直接去数据库 查询
    //     CertusFormAjax.ajax("relatedProjPur", {param: newValue}, function (res) {
    //         scope.userProjSelect2 = res.data;
    //         if (scope.userProjSelect2.length) {
    //             if (scope.userProjSelect2.length == 1) {
    //                 scope.projId = scope.userProjSelect2[0].projId;
    //                 scope.projName = scope.userProjSelect2[0].projName;
    //                 return;
    //             }
    //         }
    //         if (scope.userProjSelect2.length < 1) {
    //             if (scope.projId) {
    //                 scope.projId = null;
    //                 scope.projName = null;
    //                 return;
    //             }
    //         }
    //     })
    // });
    //
    // $scope.$watch("down.projName", function (newValue, old, scope) {
    //     debugger;
    //     if (old && newValue) {
    //         scope.projId = "";
    //         scope.projName = "";
    //         if (newValue.toUpperCase().indexOf(old.toUpperCase()) > -1) {
    //             ;
    //             nowProjName = newValue;
    //             scope.down.userProjSelect2 = scope.down.userProjSelect2.filter(isSaveProjName);
    //             if (scope.down.userProjSelect2.length) {
    //                 if (scope.down.userProjSelect2.length == 1) {
    //                     scope.down.projId = scope.down.userProjSelect2[0].projId;
    //                     scope.down.projName = scope.down.userProjSelect2[0].projName;
    //                     return;
    //                 }
    //             }
    //             if (!scope.down.userProjSelect2 || scope.down.userProjSelect2.length == 0) {
    //                 scope.down.projId = "";
    //                 scope.down.projName = "";
    //             }
    //             return;
    //         }
    //     }
    //     //直接去数据库 查询
    //     CertusFormAjax.ajax("relatedProjPur", {param: newValue}, function (res) {
    //         scope.down.userProjSelect2 = res.data;
    //         if (scope.down.userProjSelect2.length) {
    //             if (scope.down.userProjSelect2.length == 1) {
    //                 scope.down.projId = scope.down.userProjSelect2[0].projId;
    //                 scope.down.projName = scope.down.userProjSelect2[0].projName;
    //                 return;
    //             }
    //         }
    //         if (scope.down.userProjSelect2.length < 1) {
    //             if (scope.down.projId) {
    //                 scope.down.projId = null;
    //                 scope.down.projName = null;
    //                 return;
    //             }
    //         }
    //     })
    // });
}


function initProLog(res, $CertusFormAjax) {

    cell_data = res.data;
    cell_data.unshift(["", "01日", "02日", "03日", "04日", "05日", "06日", "07日", "08日", "09日", "10日",
        "11日", "12日", "13日", "14日", "15日", "16日", "17日", "18日", "19日", "20日",
        "21日", "22日", "23日", "24日", "25日", "26日", "27日", "28日", "29日", "30日", "31日"])
    if (res.data && res.data.length == 0) {
        $(document.getElementById('plogtable')).empty();
        return;
    }


    //单击事件
    Handsontable.hooks.add('afterOnCellMouseDown', callBack, hot);
    var firstRowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var firstColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("width", "130px");
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var dhoursColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        if (value > 11) {
            $(td).css("color", "#FF6C60");
        }
    };


    var container = document.getElementById('plogtable');


//单击事件的回调函数
    function callBack(event, coords, td) {

        var row = coords.row;
        var col = coords.col;

        var hours = hot.getCell(row, col, true);//取出点击内容是否为空

        var status = $("#plogbox").css('display');

        if ($(hours).html() === "" || $(hours).html() === undefined || $(hours).html() === null) {
            if (status === "block") {
                $("#lisplog").html('');
                $("#lisplog").html('<div id="ploginfoContainer" class="dlshouwen-grid-container"></div><div id="ploginfoContainerTool" class="dlshouwen-grid-toolbar-container"></div>')
                $("#plogbox").hide();
            }
            return
        } else {
            if (row != 0 && col != 0) {
                var name = hot.getCell(row, 0, true);//取出姓名
                var time = hot.getCell(0, col, true);//取出日期
                var user = $(name).html();
                var day = $(time).html();

                var start = user.indexOf('(') + 1;
                var end = user.indexOf(')');

                var dateTime = $("#year").val() + "-" + $("#month").val() + "-" + day.substring(0, day.length - 1);

                console.log('根据' + user.substring(start, end), dateTime + '查询当前日该员工的记录')

                //projIds:cell_data[coords.row][coords.col+31],
                $CertusFormAjax.ajax("everyDetailProjOkrLog", {
                    userId: cell_data[coords.row][32],
                    dayOfMonth: coords.col,
                    year: $("#year").val()
                }, function (res) {
                    // 根据工号+日期查出来的数据集
                    getGird('当前日该员工的记录', status, res.data);
                })


            }
            if (row === 0) {

                var time = hot.getCell(0, col, true);//取出日期
                var day = $(time).html();
                var dateTime = $("#year").val() + "-" + $("#month").val() + "-" + day.substring(0, day.length - 1);

                console.log('根据' + dateTime + '查询当前日所有员工的记录')

                $CertusFormAjax.ajax("everyDayProjOkrLog", {
                    year: $("#year").val(),
                    dayOfMonth: coords.col,
                    month: $("#month").val()
                }, function (res) {
                    getGird('当前日所有员工记录', status, res.data);
                })
            }
            if (col === 0) {
                var name = hot.getCell(row, 0, true);//取出姓名
                var time = hot.getCell(0, col, true);//取出日期
                var user = $(name).html();
                var day = $(time).html();

                var start = user.indexOf('(') + 1;
                var end = user.indexOf(')');

                var dateTime = $("#year").val() + "-" + $("#month").val();

                console.log('根据' + user.substring(start, end), dateTime + '查询当前员工该月份所有记录')

                $CertusFormAjax.ajax("everyUserProjOkrLog", {
                    month: $("#month").val(),
                    userId: cell_data[coords.row][32],
                    year: $("#year").val()
                }, function (res) {
                    getGird('当前月该员工所有记录', status, res.data);
                });

            }
        }
    }


// 点击分页回调值
    function getNumber(number) {
        console.log('页码' + number)
    }


// 初始化分页  id绑定声明   (总数量,初始页数,分页点击回调函数）
    $("#page").initPage(cell_data.length, 1, getNumber);

    hot = new Handsontable(container, {
        data: cell_data, //导入数据
        rowHeaders: false,
        colHeaders: false,
        fixedRowsTop: 1,
        fixedColumnsLeft: 1,
        licenseKey: 'non-commercial-and-evaluation',
        className: "htCenter htMiddle",
        width: t_width, //表宽 多余自动显示滚动条
        height: 400,//表高
        language: 'zh-CN',
        rowHeights: 40,
        // colWidths: 75,
        cells: function (row, col, prop) {//单元格渲染
            var cellProperties = {};
            if (row === 0) {
                cellProperties.renderer = firstRowRenderer;//调用首行渲染方法
            }
            if (col === 0) {
                cellProperties.renderer = firstColRenderer;//调用首列渲染方法
            }
            if (row < cell_data.length) {
                cellProperties.readOnly = true;
            }
            if (row !== 0 && col !== 0) {
                this.renderer = dhoursColRenderer;
            }

            return cellProperties;
        },
    });

    //成本列表
    var clColumns = [{
        id: 'ltime',
        title: '月份',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step1UserName',
        title: '用服确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step1ConfirmTime',
        title: '用服确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step1comment',
        title: '用服说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step2UserName',
        title: '开发确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step2ConfirmTime',
        title: '开发确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step2comment',
        title: '开发说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3UserName',
        title: '成本确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step3comment',
        title: '成本说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3ConfirmTime',
        title: '成本确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'releaseTime',
        title: '成本计算时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }];

    $CertusFormAjax.ajax('findCmcList', {}, function (response) {
        var makingOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '员工成本',
            datas: response.data,
            columns: clColumns,
            gridContainer: 'clHistryContainer',
            toolbarContainer: 'clHistryToolContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
        makingGrid.load();
    });
}

function initProLogdown(res, $CertusFormAjax) {

    cell_data_down = res.data;
    cell_data_down.unshift(["", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月",
        "11月", "12月"])
    if (res.data && res.data.length == 0) {
        $(document.getElementById('plogtabledown')).empty();
        return;
    }

    //单击事件
    Handsontable.hooks.add('afterOnCellMouseDown', callBackdown, hotdown);
    debugger
    var firstRowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var firstColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("width", "230px");
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var dhoursColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        if (value > 11) {
            $(td).css("color", "#FF6C60");
        }
    };


    var container = document.getElementById('plogtabledown');


//单击事件的回调函数
    function callBackdown(event, coords, td) {
        debugger;
        var row = coords.row;
        var col = coords.col;

        var hours = hotdown.getCell(row, col, true);//取出点击内容是否为空

        var status = $("#plogbox").css('display');

        if ($(hours).html() === "" || $(hours).html() === undefined || $(hours).html() === null) {
            if (status === "block") {
                $("#lisplog").html('');
                $("#lisplog").html('<div id="ploginfoContainer" class="dlshouwen-grid-container"></div><div id="ploginfoContainerTool" class="dlshouwen-grid-toolbar-container"></div>')
                $("#plogbox").hide();
            }
            return
        } else {
            if (row != 0 && col != 0) {
                var name = hotdown.getCell(row, 0, true);//取出姓名
                var time = hotdown.getCell(0, col, true);//取出日期
                var user = $(name).html();
                var day = $(time).html();

                var start = user.indexOf('(') + 1;
                var end = user.indexOf(')');

                var dateTime = $("#year").val() + "-" + $("#month").val() + "-" + day.substring(0, day.length - 1);

                console.log('根据' + user.substring(start, end), dateTime + '查询当前日该员工的记录')

                //projIds:cell_data[coords.row][coords.col+31],
                $CertusFormAjax.ajax("everyDetailProjOkrLogDown", {
                    userId: cell_data_down[coords.row][13],
                    monthOfYear: coords.col,
                    year: $("#year").val()
                }, function (res) {
                    // 根据工号+日期查出来的数据集
                    getGird('当前月该员工的记录', status, res.data);
                })


            }
            if (row === 0) {

                var time = hotdown.getCell(0, col, true);//取出日期
                var day = $(time).html();
                var dateTime = $("#year").val() + "-" + $("#month").val() + "-" + day.substring(0, day.length - 1);

                console.log('根据' + dateTime + '查询当前日所有员工的记录')

                $CertusFormAjax.ajax("everyDayProjOkrLogDown", {
                    year: $("#year").val(),
                    monthOfYear: coords.col
                }, function (res) {
                    getGird('当前月所有员工记录', status, res.data);
                })
            }
            if (col === 0) {
                var name = hotdown.getCell(row, 0, true);//取出姓名
                var time = hotdown.getCell(0, col, true);//取出日期
                var user = $(name).html();
                var day = $(time).html();

                var start = user.indexOf('(') + 1;
                var end = user.indexOf(')');

                var dateTime = $("#year").val() + "-" + $("#month").val();

                console.log('根据' + user.substring(start, end), dateTime + '查询当前员工该月份所有记录')

                $CertusFormAjax.ajax("everyUserProjOkrLogDown", {
                    userId: cell_data_down[coords.row][13],
                    year: $("#year").val()
                }, function (res) {
                    getGird('当前年该员工所有记录', status, res.data);
                });

            }
        }
    }


// 点击分页回调值
    function getNumber(number) {
        console.log('页码' + number)
    }


// 初始化分页  id绑定声明   (总数量,初始页数,分页点击回调函数）
    $("#page").initPage(cell_data_down.length, 1, getNumber);

    hotdown = new Handsontable(container, {
        data: cell_data_down, //导入数据
        rowHeaders: false,
        colHeaders: false,
        fixedRowsTop: 1,
        fixedColumnsLeft: 1,
        licenseKey: 'non-commercial-and-evaluation',
        className: "htCenter htMiddle",
        width: t_width, //表宽 多余自动显示滚动条
        height: 400,//表高
        language: 'zh-CN',
        rowHeights: 40,
        // colWidths: 75,
        cells: function (row, col, prop) {//单元格渲染
            var cellProperties = {};
            if (row === 0) {
                cellProperties.renderer = firstRowRenderer;//调用首行渲染方法
            }
            if (col === 0) {
                cellProperties.renderer = firstColRenderer;//调用首列渲染方法
            }
            if (row < cell_data_down.length) {
                cellProperties.readOnly = true;
            }
            if (row !== 0 && col !== 0) {
                this.renderer = dhoursColRenderer;
            }

            return cellProperties;
        },
    });

    //成本列表
    var clColumns = [{
        id: 'ltime',
        title: '月份',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step1UserName',
        title: '用服确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step1ConfirmTime',
        title: '用服确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step1comment',
        title: '用服说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step2UserName',
        title: '开发确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step2ConfirmTime',
        title: '开发确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step2comment',
        title: '开发说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3UserName',
        title: '成本确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step3comment',
        title: '成本说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3ConfirmTime',
        title: '成本确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'releaseTime',
        title: '成本计算时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }];

    // $CertusFormAjax.ajax('findCmcList', {}, function (response) {
    //     var makingOption = {
    //         lang: 'zh-cn',
    //         ajaxLoad: false,
    //         extraWidth: 20,
    //         // loadURL:'url',
    //         exportFileName: '员工成本',
    //         datas: response.data,
    //         columns: clColumns,
    //         gridContainer: 'clHistryContainer',
    //         toolbarContainer: 'clHistryToolContainer',
    //         tools: '',
    //         pageSize: 10,
    //         pageSizeLimit: [10, 15, 20]
    //     };
    //     var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
    //     makingGrid.load();
    // });
}

function initProLogdownSimple(res, $CertusFormAjax) {

    cell_data_down = res.data;
    cell_data_down.unshift(["", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月",
        "11月", "12月"])
    if (res.data && res.data.length == 0) {
        $(document.getElementById('plogtabledown')).empty();
        return;
    }

    //单击事件
    Handsontable.hooks.add('afterOnCellMouseDown', callBackdown, hotdown);
    debugger
    var firstRowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var firstColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        $(td).css("width", "330px");
        $(td).css("color", "#797979");
        $(td).css("background-color", "#eee");
    };

    var dhoursColRenderer = function (instance, td, row, col, prop, value, cellProperties) {
        Handsontable.renderers.TextRenderer.apply(this, arguments);
        if (value > 11) {
            $(td).css("color", "#FF6C60");
        }
    };


    var container = document.getElementById('plogtabledown');


//单击事件的回调函数
    function callBackdown(event, coords, td) {
    }


// 点击分页回调值
    function getNumber(number) {
        console.log('页码' + number)
    }


// 初始化分页  id绑定声明   (总数量,初始页数,分页点击回调函数）
    $("#page").initPage(cell_data_down.length, 1, getNumber);

    hotdown = new Handsontable(container, {
        data: cell_data_down, //导入数据
        rowHeaders: false,
        colHeaders: false,
        fixedRowsTop: 1,
        fixedColumnsLeft: 1,
        licenseKey: 'non-commercial-and-evaluation',
        className: "htCenter htMiddle",
        width: t_width, //表宽 多余自动显示滚动条
        height: 400,//表高
        language: 'zh-CN',
        rowHeights: 40,
        // colWidths: 75,
        cells: function (row, col, prop) {//单元格渲染
            var cellProperties = {};
            if (row === 0) {
                cellProperties.renderer = firstRowRenderer;//调用首行渲染方法
            }
            if (col === 0) {
                cellProperties.renderer = firstColRenderer;//调用首列渲染方法
            }
            if (row < cell_data_down.length) {
                cellProperties.readOnly = true;
            }
            if (row !== 0 && col !== 0) {
                this.renderer = dhoursColRenderer;
            }

            return cellProperties;
        },
    });

    //成本列表
    var clColumns = [{
        id: 'ltime',
        title: '月份',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step1UserName',
        title: '用服确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step1ConfirmTime',
        title: '用服确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step1comment',
        title: '用服说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step2UserName',
        title: '开发确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step2ConfirmTime',
        title: '开发确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'step2comment',
        title: '开发说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3UserName',
        title: '成本确认人',
        type: 'string',
        columnClass: 'text-center',
        width: 60
    }, {
        id: 'step3comment',
        title: '成本说明',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'step3ConfirmTime',
        title: '成本确认时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }, {
        id: 'releaseTime',
        title: '成本计算时间',
        type: 'string',
        columnClass: 'text-center',
        width: 100
    }];

    // $CertusFormAjax.ajax('findCmcList', {}, function (response) {
    //     var makingOption = {
    //         lang: 'zh-cn',
    //         ajaxLoad: false,
    //         extraWidth: 20,
    //         // loadURL:'url',
    //         exportFileName: '员工成本',
    //         datas: response.data,
    //         columns: clColumns,
    //         gridContainer: 'clHistryContainer',
    //         toolbarContainer: 'clHistryToolContainer',
    //         tools: '',
    //         pageSize: 10,
    //         pageSizeLimit: [10, 15, 20]
    //     };
    //     var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
    //     makingGrid.load();
    // });
}